import {reqBanner} from "../../request/api"
//初始值
const initState = {
    banner:[]
}

//actionTypes
const types = {
    //修改 
    CHANGE_BANNER:"MINE_CHANGE_BANNER"
}

//reducer 修改数据
const reducer = (state = initState, action) => {
    switch (action.type) {
        case types.CHANGE_BANNER:
            return {
                ...state,
                banner:action.arr
            }
        default:
            return state;
    }

}

//actionCreators组件派发任务
export const actions = {
    //修改，请求
changeBanner:(arr)=>({type:types.CHANGE_BANNER,arr}),
reqBanner:()=>(dispatch,getState)=>{
    reqBanner().then(res=>{
        if(res.data.code==200){
            dispatch(actions.changeBanner(res.data.list))
        }
    })
}
}

//selectors 导出数据
export const getBanner=(state)=>{
   return  state.mine.banner
}

export default reducer